﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class DispatchDA : IDispatchDA
    {
        private string CREATED_BY = "@CREATED_BY";
        private string DELIVERY_DATE = "@DELIVERY_DATE";
        private string DISPATCH_ID = "@DISPATCH_ID";
        private string IS_ACTIVE = "@IS_ACTIVE";
        private string PICKUP_DATE = "@PICKUP_DATE";
        private string PLAN_TRANSPORT_MODE = "@PLAN_TRANSPORT_MODE";
        private string REMARK = "@REMARK";
        private string SHIPMENT_COMMAND = "@SHIPMENT_COMMAND";
        private string SQL_CHECK_DISPATCH_ID_UNIQUE = " SELECT COUNT(1) FROM @_@DISPATCH WHERE DISPATCH_ID = @DISPATCH_ID ";
        private string SQL_DELETE_DISPATCH = " DELETE FROM @_@DISPATCH WHERE DISPATCH_ID = @DISPATCH_ID ";
        private string SQL_INSERT_DISPATCH = " INSERT INTO @_@DISPATCH ( WH_ID, DISPATCH_ID, PICKUP_DATE, DELIVERY_DATE, STATUS, PLAN_TRANSPORT_MODE, SHIPMENT_COMMAND, UDF1, UDF2, UDF3, UDF4, UDF5, UDF6, UDF7, UDF8, UDF9, UDF10, REMARK, IS_ACTIVE, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @DISPATCH_ID, @PICKUP_DATE, @DELIVERY_DATE, @STATUS, @PLAN_TRANSPORT_MODE, @SHIPMENT_COMMAND, @UDF1, @UDF2, @UDF3, @UDF4, @UDF5, @UDF6, @UDF7, @UDF8, @UDF9, @UDF10, @REMARK, @IS_ACTIVE, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_DISPATCH = "SELECT  DIS.ROWID, DIS.WH_ID, DIS.DISPATCH_ID, DIS.PICKUP_DATE, DIS.DELIVERY_DATE,   DIS.STATUS as  STATUS,   T.[TEXT] AS DIS_STATUS,  DIS.PLAN_TRANSPORT_MODE ,  T1.[TEXT] AS DIS_PLAN_TRANSPORT_MODE ,  DIS.SHIPMENT_COMMAND, DIS.UDF1, DIS.UDF2, DIS.UDF3, DIS.UDF4, DIS.UDF5, DIS.UDF6, DIS.UDF7, DIS.UDF8, DIS.UDF9, DIS.UDF10, DIS.REMARK, DIS.IS_ACTIVE, DIS.TS, DIS.CREATED_BY, DIS.CREATED_DATE, DIS.UPDATED_BY, DIS.UPDATED_DATE    FROM  @_@DISPATCH as DIS  LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = DIS.STATUS AND SCD.SYS_CODE_TYPE = 'DispatchStatus'    LEFT JOIN @_@SYS_CODE_DETAIL SCD1 ON SCD1.SYS_CODE = DIS.PLAN_TRANSPORT_MODE AND SCD1.SYS_CODE_TYPE = 'TransportMode'   LEFT JOIN sysadm.TRANSLATION T ON 'DispatchStatus.'+ DIS.STATUS = T.ITEM_ID       AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE  LEFT JOIN sysadm.TRANSLATION T1 ON 'TransportMode.'+ DIS.PLAN_TRANSPORT_MODE = T1.ITEM_ID       AND  T1.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T1.LANG+'-'+T1.COUNTRY = @LANGUAGE ";
        private string SQL_UPDATE_DISPATCH = " UPDATE @_@DISPATCH SET WH_ID = @WH_ID, PICKUP_DATE = @PICKUP_DATE, DELIVERY_DATE = @DELIVERY_DATE, STATUS = @STATUS, PLAN_TRANSPORT_MODE = @PLAN_TRANSPORT_MODE, SHIPMENT_COMMAND = @SHIPMENT_COMMAND, UDF1 = @UDF1, UDF2 = @UDF2, UDF3 = @UDF3, UDF4 = @UDF4, UDF5 = @UDF5, UDF6 = @UDF6, UDF7 = @UDF7, UDF8 = @UDF8, UDF9 = @UDF9, UDF10 = @UDF10, REMARK = @REMARK, IS_ACTIVE = @IS_ACTIVE, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE DISPATCH_ID = @DISPATCH_ID  ";
        private string STATUS = "@STATUS";
        private string TS = "@TS";
        private string UDF1 = "@UDF1";
        private string UDF10 = "@UDF10";
        private string UDF2 = "@UDF2";
        private string UDF3 = "@UDF3";
        private string UDF4 = "@UDF4";
        private string UDF5 = "@UDF5";
        private string UDF6 = "@UDF6";
        private string UDF7 = "@UDF7";
        private string UDF8 = "@UDF8";
        private string UDF9 = "@UDF9";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckDispatchIDUnique(string dispatchID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@DISPATCH_ID", dispatchID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_DISPATCH_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckDispatchIDUnique(DataBase dataBase, DbTransaction tran, string dispatchID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@DISPATCH_ID", dispatchID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_DISPATCH_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteDispatch(List<string> dispatchID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < dispatchID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@DISPATCH_ID", dispatchID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_DISPATCH.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteDispatch(DataBase dataBase, DbTransaction tran, List<string> dispatchID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < dispatchID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@DISPATCH_ID", dispatchID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_DISPATCH.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllDispatch(string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_DISPATCH.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            return DBHelper.ExecuteDataSet(CommandType.Text, sql, paras);
        }

        public DataSet GetAllDispatch(DataBase dataBase, DbTransaction tran, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_DISPATCH.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql, paras);
        }

        public DispatchInfo GetDispatchByID(string dispatchID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_DISPATCH.Replace("@_@", whLoginID) + " WHERE DISPATCH_ID = @DISPATCH_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@DISPATCH_ID", dispatchID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            DispatchInfo dispatchInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    DateTime CS00003;
                    dispatchInfo = new DispatchInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["DISPATCH_ID"].ToString(), (reader["PICKUP_DATE"].ToString() != "") ? DateTime.Parse(reader["PICKUP_DATE"].ToString()) : (CS00003 = new DateTime()), (reader["DELIVERY_DATE"].ToString() != "") ? DateTime.Parse(reader["DELIVERY_DATE"].ToString()) : (CS00003 = new DateTime()), reader["STATUS"].ToString(), reader["PLAN_TRANSPORT_MODE"].ToString(), reader["SHIPMENT_COMMAND"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
                }
            }
            return dispatchInfo;
        }

        public DispatchInfo GetDispatchByID(DataBase dataBase, DbTransaction tran, string dispatchID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_DISPATCH.Replace("@_@", whLoginID) + " WHERE DISPATCH_ID = @DISPATCH_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@DISPATCH_ID", dispatchID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            DispatchInfo dispatchInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                DateTime CS00003;
                dispatchInfo = new DispatchInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["DISPATCH_ID"].ToString(), (reader["PICKUP_DATE"].ToString() != "") ? DateTime.Parse(reader["PICKUP_DATE"].ToString()) : (CS00003 = new DateTime()), (reader["DELIVERY_DATE"].ToString() != "") ? DateTime.Parse(reader["DELIVERY_DATE"].ToString()) : (CS00003 = new DateTime()), reader["STATUS"].ToString(), reader["PLAN_TRANSPORT_MODE"].ToString(), reader["SHIPMENT_COMMAND"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return dispatchInfo;
        }

        public DataSet GetDispatchByQueryList(List<string> sqlWhere, DispatchQueryEntity dispatchQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_DISPATCH.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!dispatchQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, dispatchQuery.CurrentPage, dispatchQuery.PageSize, dispatchQuery.SortField, dispatchQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetDispatchByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, DispatchQueryEntity dispatchQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_DISPATCH.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (dispatchQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, dispatchQuery.CurrentPage, dispatchQuery.PageSize, dispatchQuery.SortField, dispatchQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            }
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public int InsertDispatch(DispatchInfo dispatchInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    dispatchInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_Dispatch_Parameters(dispatchInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_DISPATCH.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertDispatch(DataBase dataBase, DbTransaction tran, DispatchInfo dispatchInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    dispatchInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_Dispatch_Parameters(dispatchInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_DISPATCH.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_Dispatch_Parameters(DispatchInfo dispatchInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { 
                new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.DISPATCH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.PICKUP_DATE, SqlDbType.DateTime, 8), new SqlParameter(this.DELIVERY_DATE, SqlDbType.DateTime, 8), new SqlParameter(this.STATUS, SqlDbType.VarChar, 30), new SqlParameter(this.PLAN_TRANSPORT_MODE, SqlDbType.VarChar, 30), new SqlParameter(this.SHIPMENT_COMMAND, SqlDbType.VarChar, 30), new SqlParameter(this.UDF1, SqlDbType.VarChar, 30), new SqlParameter(this.UDF2, SqlDbType.VarChar, 30), new SqlParameter(this.UDF3, SqlDbType.VarChar, 30), new SqlParameter(this.UDF4, SqlDbType.VarChar, 30), new SqlParameter(this.UDF5, SqlDbType.VarChar, 30), new SqlParameter(this.UDF6, SqlDbType.VarChar, 30), new SqlParameter(this.UDF7, SqlDbType.VarChar, 30), new SqlParameter(this.UDF8, SqlDbType.VarChar, 30), new SqlParameter(this.UDF9, SqlDbType.VarChar, 30), 
                new SqlParameter(this.UDF10, SqlDbType.VarChar, 30), new SqlParameter(this.REMARK, SqlDbType.VarChar, 100), new SqlParameter(this.IS_ACTIVE, SqlDbType.VarChar, 1), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 30), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 30)
             };
            if (!string.IsNullOrEmpty(dispatchInfo.WhID))
            {
                paramArray[0].Value = dispatchInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = dispatchInfo.DispatchID;
            DateTime CS00003 = new DateTime();
            if (dispatchInfo.PickupDate != CS00003)
            {
                paramArray[2].Value = dispatchInfo.PickupDate;
            }
            else
            {
                paramArray[2].Value = DBNull.Value;
            }
            if (dispatchInfo.DeliveryDate != new DateTime())
            {
                paramArray[3].Value = dispatchInfo.DeliveryDate;
            }
            else
            {
                paramArray[3].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Status))
            {
                paramArray[4].Value = dispatchInfo.Status;
            }
            else
            {
                paramArray[4].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.PlanTransportMode))
            {
                paramArray[5].Value = dispatchInfo.PlanTransportMode;
            }
            else
            {
                paramArray[5].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.ShipmentCommand))
            {
                paramArray[6].Value = dispatchInfo.ShipmentCommand;
            }
            else
            {
                paramArray[6].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Udf1))
            {
                paramArray[7].Value = dispatchInfo.Udf1;
            }
            else
            {
                paramArray[7].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Udf2))
            {
                paramArray[8].Value = dispatchInfo.Udf2;
            }
            else
            {
                paramArray[8].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Udf3))
            {
                paramArray[9].Value = dispatchInfo.Udf3;
            }
            else
            {
                paramArray[9].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Udf4))
            {
                paramArray[10].Value = dispatchInfo.Udf4;
            }
            else
            {
                paramArray[10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Udf5))
            {
                paramArray[11].Value = dispatchInfo.Udf5;
            }
            else
            {
                paramArray[11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Udf6))
            {
                paramArray[12].Value = dispatchInfo.Udf6;
            }
            else
            {
                paramArray[12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Udf7))
            {
                paramArray[13].Value = dispatchInfo.Udf7;
            }
            else
            {
                paramArray[13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Udf8))
            {
                paramArray[14].Value = dispatchInfo.Udf8;
            }
            else
            {
                paramArray[14].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Udf9))
            {
                paramArray[15].Value = dispatchInfo.Udf9;
            }
            else
            {
                paramArray[15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Udf10))
            {
                paramArray[0x10].Value = dispatchInfo.Udf10;
            }
            else
            {
                paramArray[0x10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(dispatchInfo.Remark))
            {
                paramArray[0x11].Value = dispatchInfo.Remark;
            }
            else
            {
                paramArray[0x11].Value = DBNull.Value;
            }
            paramArray[0x12].Value = dispatchInfo.IsActive;
            paramArray[0x13].Value = dispatchInfo.CreatedBy;
            paramArray[20].Value = dispatchInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdateDispatch(DispatchInfo dispatchInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    dispatchInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_Dispatch_Parameters(dispatchInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_DISPATCH.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateDispatch(DataBase dataBase, DbTransaction tran, DispatchInfo dispatchInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    dispatchInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_Dispatch_Parameters(dispatchInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_DISPATCH.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

